<?php

class AsesorexternoController extends Controller
{
	public $layout='//layouts/templete';
	public function actionIndex()
	{
		
            
			$total=Asesorexterno::model()->with('asesorempresa')->count();
			$pages=new CPagination();
			$pages->pageSize=15;
			$criteria=new CDbCriteria();
			$criteria->limit=$pages->limit;
			$criteria->offset=$pages->offset;

            $model   =    Asesorexterno::model()->with('asesorempresa')->findAll($criteria);
		
		$this->render('index', array('model' =>$model,'pages'=>$pages));
	}
	public function actionNuevo()
	{
		$tipo=Yii::app()->user->getState('id_tipo');
		$id_usuario=Yii::app()->user->getState('id_usuario');
		if($tipo==='ADMIN' && $id_usuario>0)
		{
				$model=new Asesorexterno;

    		// uncomment the following code to enable ajax-based validation
			    /*
			    if(isset($_POST['ajax']) && $_POST['ajax']==='asesorexterno-formAsesorExterno-form')
			    {
			        echo CActiveForm::validate($model);
			        Yii::app()->end();
			    }
			    */

		    if(isset($_POST['Asesorexterno']))
		    {
		        $model->attributes=$_POST['Asesorexterno'];
		        if($model->validate())
		        {
		            // form inputs are valid, do something here
		            if($model->save())
		            		$this->redirect(array('index'));
		           //return;
		        }
    		}
    	$this->render('formAsesorExterno',array('model'=>$model));
		}
		else
		{
			$this->redirect(array('site/index'));
		}
	}
public function actionUpdate($id)
{
		$tipo=Yii::app()->user->getState('id_tipo');
		$id_usuario=Yii::app()->user->getState('id_usuario');
		if($tipo==='ADMIN' && $id_usuario>0)
		{
			$model=Asesorexterno::model()->findByPk($id);
			
			
			if(isset($_POST['Asesorexterno']))
			{
				
				$model->attributes=$_POST['Asesorexterno'];
				
				if($model->save())
				{
					$this->redirect(array('index'));
				}
			}
		
		$this->render('formAsesorExterno',array('model'=>$model));	
		
		}
		else
		{
			$this->redirect(array('site/index'));
		}

}

/*funcion eliminar**/
public function actionDelete($id)
{
	$tipo=Yii::app()->user->getState('id_tipo');
		$id_usuario=Yii::app()->user->getState('id_usuario');
		if($tipo==='ADMIN' && $id_usuario>0)
		{
			$model=Asesorexterno::model()->deleteByPk($id);
			$this->redirect(array('index'));
		}
		else
		{
			$this->redirect(array('site/index'));
		}
}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}